<template>
  <div>
    <div class="header_search_nav search_form">
      <div class="ipt_left">
        <el-form ref="queryParams" :model="queryParams" label-width="96px">
          <el-row :gutter="24">
            <el-col :span="6">
              <el-form-item label="门店名称" prop="name">
                <el-input
                  v-model="queryParams.name"
                  placeholder="请输入任务名称"
                  class="w-100"
                  @keyup.enter.native="handleQuery"
                ></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="封账状态" prop="orderCloseStatus">
                <el-select
                  v-model="queryParams.orderCloseStatus"
                  placeholder="请选择"
                  filterable
                  clearable
                >
                  <el-option
                    v-for="(item, index) in orderCloseStatusOptions"
                    :key="index"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>

      <div class="btn_right">
        <button class="btn1" @click="handleQuery">筛选</button>
        <button class="btn2" @click="resetQuery">重置</button>
      </div>
    </div>
    <div class="table_card">
      <!-- 上部分 title -->
      <div class="table_card_top">
        <span class="solid_left"></span>
        <div class="table_card_title">门店封账</div>
      </div>

      <div class="table_list">
        <el-table :data="tableData" stripe style="width: 100%">
          <el-table-column prop="name" label="门店名称"></el-table-column>
          <el-table-column prop="orderCloseStatus" label="封账状态">
            <template slot-scope="scope">
              <!-- {{orderCloseStatusObj[scope.row.orderCloseStatus]}} -->
              <div @click="ActionSwitch(scope.row)" class="SwitchBox">
                <div class="switchMark"></div>
                <el-switch
                  v-model="scope.row.orderCloseStatus"
                  active-color="#13ce66"
                  inactive-color="#ff4949"
                  active-value="Y"
                  inactive-value="N"
                >
                </el-switch>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="orderCloseTime"
            label="封账时间"
          ></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="EditClosureTime(scope.row)"
                >修改封账时间</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          :total="total"
          :page.sync="queryParams.pageNo"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </div>

    <!-- 修改封账时间 -->
    <el-dialog
      title="修改封账时间"
      :visible.sync="EditTimeDialog"
      width="30%"
      :before-close="handleCloseEditTime"
    >
      <span>
        <el-form
          ref="EditTimeForm"
          :model="EditTimeForm"
          :rules="EditTimeFormRules"
          label-width="120px"
        >
          <el-form-item label="修改封账时间" prop="orderCloseTime">
            <el-date-picker
              v-model="EditTimeForm.orderCloseTime"
              type="datetime"
              placeholder="选择修改封账时间"
              value-format="yyyy-MM-dd HH:mm:ss"
              class="w-100"
            >
            </el-date-picker>
          </el-form-item>
        </el-form>
      </span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleCloseEditTime">取 消</el-button>
        <el-button type="primary" @click="SaveEditTime">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getStoreClosureList,
  StatusAction,
  EditCloseTime,
} from "@/api/bpm/StoreClosure";
export default {
  name: "EryuoaRaskLog",

  data() {
    return {
      EditTimeDialog: false,
      EditTimeForm: {
        id: "",
        orderCloseTime: "",
      },
      EditTimeFormRules: {
        orderCloseTime: [
          { required: true, message: "请选择", trigger: "blur" },
        ],
      },
      loading: false,
      activeIndex: 1,
      currentIndex: 1,
      tableData: [],
      StoreSlist: [],
      title: "",
      value: "",
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        orderCloseStatus: "", // 执行状态
        name: "", // 任务名称
      },

      orderCloseStatusOptions: [
        {
          value: "Y",
          label: "开启",
        },
        {
          value: "N",
          label: "关闭",
        },
      ],

      //   orderCloseStatusObj:{
      //     "Y":"开启",
      //     "N":"关闭",
      //   },

      total: 0,
    };
  },

  created() {
    this.getList();
  },

  mounted() {},

  methods: {
    // 修改封账时间
    EditClosureTime(row) {
      this.EditTimeDialog = true;
      this.EditTimeForm.id = row.id;
      this.EditTimeForm.orderCloseTime = row.orderCloseTime;
    },

    SaveEditTime() {
      this.$refs["EditTimeForm"].validate((valid) => {
        if (valid) {
          EditCloseTime({
            id: this.EditTimeForm.id,
            orderCloseTime: this.EditTimeForm.orderCloseTime,
          })
            .then((Res) => {
              const { code } = Res;
              if (code === 0) {
                this.$message({
                  type: "success",
                  message: "操作成功!",
                });
                this.getList();
                this.handleCloseEditTime();
              }
            })
            .catch((err) => {});
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    handleCloseEditTime() {
      this.resetFormData("EditTimeForm");
      this.$nextTick(() => {
        this.EditTimeDialog = false;
      });
    },
    ActionSwitch(row) {
      let actionText = row.orderCloseStatus === "N" ? "开启" : "关闭";
      this.$confirm(`确认要${actionText}封账吗？`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //   let newStatus = row.orderCloseStatus === "Y" ? "N" : "Y";
          StatusAction({
            id: row.id,
          })
            .then((res) => {
              const { code } = res;
              if (code === 0) {
                this.$message({
                  type: "success",
                  message: "操作成功!",
                });
                this.getList();
              }
            })
            .catch((err) => {});
        })
        .catch(() => {});
    },
    resQ() {
      this.queryParams.pageNo = 1;
      this.total = 0;
      this.tableData = [];
      this.getList();
    },

    getList() {
      this.loading = true;
      getStoreClosureList(this.queryParams)
        .then((res) => {
          console.log(res);
          this.loading = false;
          const { code, data } = res;
          if (code === 0) {
            this.tableData = data.list;
            this.total = data.total;
            // if (data.list.length === 0 && this.queryParams.pageNo > 1) {
            //   this.queryParams.pageNo = this.queryParams.pageNo - 1;
            //   this.getList();
            // }
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },

    // 筛选
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },

    /** 重置按钮操作 */
    resetQuery() {
      this.resetFormData("queryParams");
      this.handleQuery();
    },

    // 表单重置
    resetFormData(formName) {
      console.log(this.$refs[formName]);
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style lang="scss" scoped>
.w-200 {
  width: 200px;
  background: #ffffff;
  border-radius: 4px;
}

.client_name {
  font-size: 14px;
  font-weight: 400;
  color: #0052d9;
}

.give {
  height: 40px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
  margin-top: 40px;
  line-height: 40px;
}

.el-form-item {
  margin-bottom: 20px;
}

.recharge_form {
  padding: 10px 24px;
}

.memberName {
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.85);
}
.el_row_item {
  margin-bottom: 10px;
}
.el_row_date {
  margin-top: 20px;
}
.el_row_reason {
  margin-top: 10px;
}

.el_row_date {
  .el-form-item {
    margin-bottom: 0px;
  }
}

.separate_left {
  width: 1px;
  height: 14px;
  // background: #e9e9e9;
  margin-right: 12px;
}
.separate_right {
  width: 1px;
  height: 14px;
  // background: #e9e9e9;
  margin-left: 12px;
}

.check {
  font-size: 12px;
  color: #0052d9;
}

.list_Stores {
  height: 22px;
  font-size: 14px;
  font-weight: 400;
  color: rgba(0, 0, 0, 0.9);
  line-height: 22px;
  .list_Stores_item {
    height: 46px;
    line-height: 46px;
    background: #ffffff;
    padding-left: 47px;
    border-bottom: 1px solid #e7e7e7;
  }
}

.AddRules_box {
  padding: 0 24px;
  .Rules_form_box {
    display: flex;
    .Rules_form_select {
      margin-right: 10px;
    }
  }
}

.radio_box {
  display: flex;
  margin-bottom: 10px;
}

.up_ipt {
  width: 300px;
  margin-right: 20px;
}
.down_ipt {
  width: 300px;
  margin-left: 10px;
}
.percentIcon {
  position: absolute;
  top: 55px;
  right: -15px;
}

.SwitchBox {
  position: relative;
  .switchMark {
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 99;
  }
}
</style>
